import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "../store";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:'/welcome'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login')
  },
  {
    path: '/main',
    name: 'Main',
    redirect:'/welcome',
    component: () => import('../views/Main'),
    meta:{
      title:'物资管理系统'
    },
    children:[
      {
        path: '/users',
        name: 'Users',
        component: () => import('../views/system/user/Users')
      },{
        path: '/welcome',
        name: 'Welcome',
        component: () => import('../views/system/user/welcome')
      },{
        path: '/roles',
        name: 'Roles',
        component: () => import('../views/system/Role/roles')
      },
      {
        path: '/departments',
        name: 'Departments',
        component: () => import('../views/system/department/Departments')
      },
      {
        path: '/notices',
        name: 'Notices',
        component: () => import('../views/system/notices/Notices')
      },
      {
        path: '/menus',
        name: 'Menus',
        component: () => import('../views/system/menus/Menus')
      },
      {
        path: '/attachment',
        name: 'Attachment',
        component: () => import('../views/system/attachments/Attachment')
      },
      /**********************************业务模块的路由******************************/
      {
        path: '/category',
        name: 'Category',
        component: () => import('../views/business/category/Category')
      },
      {
        path: '/products',
        name: 'Products',
        component: () => import('../views/business/product/Products')
      },
      {
        path: '/inStocks',
        name: 'InStocks',
        component: () => import('../views/business/in-stocks/InStocks'),
      },
      {
        path: '/addStocks',
        name: 'addStocks',
        component: () => import('../views/business/in-stocks/addStocks')
      },
      {
        path: '/stocks',
        name: 'Stocks',
        component: () => import('../views/business/stocks/Stocks')
      },
      {
        path: '/suppliers',
        name: 'Suppliers',
        component: () => import('../views/business/suppliers/Suppliers')
      },
      {
        path: '/consumers',
        name: 'Consumers',
        component: () => import('../views/business/consumers/Consumers')
      },
      {
        path: '/outStocks',
        name: 'OutStock',
        component: () => import('../views/business/out-stock/OutStock')
      },
      {
        path: '/Publish',
        name: 'Publish',
        component: () => import('../views/business/publish/Publish')
      },
      {
        path: '/*',
        name: 'error',
        component:()=>import('../views/error/404')
      }
    ]
  },{
  path: "/*",
    name:'error',
    component:()=>import('../views/error/404')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  let token= localStorage.getItem("token");
  if(to.path==="/login") return  next();
  if(!token)return router.replace('/login')
  document.title="新冠物资管理系统"
  next();
})

export default router
